package com.example.controller.institutioncare.institutionadmin;

import com.example.bean.carecommunity.SafetySystem;
import com.example.bean.institutioncare.institutionadmin.Basicdata;
import com.example.bean.institutioncare.institutionadmin.BasicdataVo;
import com.example.service.institutioncare.institutionadmin.BasicService;
import com.example.utils.Resss;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

/**
 * 机构养老/机构管理/基本信息
 */
@CrossOrigin
@RestController
@RequestMapping("/basic")
public class BasicdataController{

    @Autowired
    BasicService basicService;

    @PostMapping("/selectPageInfo")
    public Resss selectPageInfo(@RequestBody BasicdataVo vo){
        return new Resss().data("basic",basicService.selectPageInfo(vo));
    }

    @PostMapping("/addInfo")
    public Resss addInfo(){
        return new Resss().data("inner",basicService.addInner()).data("inners",basicService.addInners());
    }

    @PostMapping("/addPost")
    public Resss addPost(@RequestBody Prams ttt){
        String rrr="";
        for(String sss:ttt.getBasics().getReasons()){
            rrr+=sss+",";
        }
        ttt.getBasics().setReason(rrr);
        return new Resss().code(basicService.addBasicSafetyInnsss(ttt.getBasics(),ttt.getSafety(),ttt.getInnersss()));
    }

    @PostMapping("/putBasicdata/{noid}")
    public Resss putBasicdata(@PathVariable("noid")String noid){
        return new Resss().data("dsss",basicService.putBasicdata(noid));
    }

    @PostMapping("/putSafetym/{noid}")
    public Resss putSafetym(@PathVariable("noid")String noid){
        return new Resss().data("dsss",basicService.putSafetym(noid));
    }

    @PostMapping("/updateId")
    public Resss updateId(@RequestBody Prams ttt){
        String rrr="";
        for(String sss:ttt.getBasics().getReasons()){
            rrr+=sss+",";
        }
        ttt.getBasics().setReason(rrr);
        return new Resss().code(basicService.updateId(ttt.getBasics(),ttt.getSafety(),ttt.getInnersss()));
    }

    @DeleteMapping("/delete/{noid}")
    public Resss delete(@PathVariable("noid")String noid){
        return new Resss().code(basicService.delete(noid));
    }
}

@Component
@Data
@NoArgsConstructor
@AllArgsConstructor
class Prams{
    /**
     * 安全
     * 基本新增
     * */
    private Basicdata basics;
    private SafetySystem safety;
    private String[] innersss;
}